<?php

namespace app\queue\redis;

use app\common\library\RedisKey;
use app\common\library\Show;
use app\queue\BaseJob;
use GatewayWorker\Lib\Gateway;
use support\Redis;

class CloseClient extends BaseJob
{
    // 要消费的队列名
    public $queue = 'CloseClient';

    /**
     * Notes:关闭规定时间内未通讯的链接
     * @param $data
     * @return array
     */
    public function doJob($data)
    {
        try {
            $client_id = $data['client_id'];
            if (Redis::get(RedisKey::clientBind($client_id))) {
                return Show::success();
            }
            var_dump("closeClient ".date('Y-m-d H:i:s')." ".$client_id);
            Gateway::closeClient($client_id);
            return Show::success();
        } catch (\Throwable $e) {
            return Show::error($e->getMessage());
        }
    }
}